/**
 * 当天没有日程，展示空界面
 */
import React from "react";
import { View, Text, ScrollView, RefreshControl } from "react-native";
import VisitData from "../module/VisitData";
import { R } from '../../../core';
import { BProps, BState ,BaseComponent} from "../../index";

interface IProps extends BProps {
  dataSource?: any;
  showItems?: any;
  visitData?: VisitData;
  openPlanDetail?: (item: any) => void;
}

interface IState extends BState {
  isLoading: boolean;
}

export class NoVisitList extends BaseComponent<IProps, IState> {
  constructor(props: IProps) {
    super(props);
    this.state = {
      isLoading: false,
    };
  }

  render() {
    return (
      <ScrollView
        style={{ flex: 1 }}
        refreshControl={
          <RefreshControl
            refreshing={this.state.isLoading}
            onRefresh={() => {
              this.props.actions.refreshData();
            }}
          />
        }
      >
        <View style={R.styles.box}>
          <Text style={R.styles.text}>{"无数据"}</Text>
        </View>
      </ScrollView>
    );
  }
}

export class VisitList extends BaseComponent<IProps, IState> {
  constructor(props: IProps) {
    super(props);
    this.state = {
      isLoading: false,
    };
  }

  //当数据不相同，才渲染
  // shouldComponentUpdate(nextProps: any, nextState: any) {
  //   return (this.props.dataSource.show != nextProps.dataSource.show)
  //     || (this.props.dataSource.showPop != nextProps.dataSource.showPop);
  // }

  render() {
    let layout =
      this.props.visitData &&
      this.props.visitData.getDataWithLayout(
        this.props.componentId,
        this.props.dataSource,
        this.props.showItems,
        this.props.actions,
        this.props.openPlanDetail,
      );
    return (
      <View
        style={{
          backgroundColor: "#FBFBFC",
          flexDirection: "row",
          alignItems: "center",
          paddingTop: 10,
          paddingLeft: 10,
          paddingRight: 10,
        }}
      >
        {layout || null}
      </View>
    );
  }
}
